<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
  <div id="app">
    <cpn
        :number1="num1" :number2="num2"
        @num1-change="num1Change" @num2-change="num2Change"
    ></cpn>
  </div>

  <template id="cpn">
    <div>
      <h2>{{number1}}</h2>
      <input type="text" :value="childNum1" @input="num1Input"/>
      <h2>{{number2}}</h2>
      <input type="text" :value="childNum2" @input="num2Input"/>
    </div>
  </template>

  <script src="https://vuejs.org/js/vue.js"></script>
  <script>
    new Vue({
      el: "#app",
      data: {
        num1: 1,
        num2: 0
      },
      methods: {
        num1Change(value) {
          this.num1 = parseInt(value)
        },
        num2Change(value) {
          this.num2 = parseInt(value)
        }
      },
      components: {
        cpn: {
          template: "#cpn",
          props: {
            number1: Number,
            number2: Number
          },
          data() {
            return {
              childNum1: this.number1,
              childNum2: this.number2
            }
          },
          methods: {
            num1Input(event) {
              this.childNum1 = event.target.value;
              this.$emit("num1-change", this.childNum1);
            },
            num2Input(event) {
              this.childNum2 = event.target.value;
              this.$emit("num2-change", this.childNum2);
            }
          }
        }
      }
    });
  </script>
</body>
</html>
